<script setup>
import {
  lingchuangPoint,
  lingchuangIncome,
  hospital,
  culturePublication,
  cultureContract,
  community,
  childElder,
  gymIncome,
  chenganAmount,
  allExport,
} from "@/api/dailyPaper/statistical";
import { useExport, useList } from "@/hooks/useDaily";
import {
  childElderlyColumns,
  communityColumns,
  labHospitalColumns,
  culturalLvColumns,
  culturalColumns,
  lingchuangPointColumns,
  lingchuangColumns,
  gymColumns,
  chenganColumns,
} from "./columns";

const { dataSource: childElderList, CustomTable } = useList({
  getFn: childElder,
});
const { dataSource: communityList } = useList({
  getFn: community,
});
const { dataSource: labList } = useList({
  getFn: hospital,
});
const { dataSource: culturePubList } = useList({
  getFn: culturePublication,
});
const { dataSource: cultureList } = useList({
  getFn: cultureContract,
});
const { dataSource: lingchuangPointList } = useList({
  getFn: lingchuangPoint,
});
const { dataSource: lingchuangIncomeList } = useList({
  getFn: lingchuangIncome,
});
const { dataSource: gymList } = useList({
  getFn: gymIncome,
});
const { dataSource: chenganList } = useList({
  getFn: chenganAmount,
});

const { onExport } = useExport({
  exportFn: allExport,
  fileName: "统计导出",
});
const rowSpan = ({ row, column, rowIndex, columnIndex }, list) => {
  if (columnIndex === 0) {
    if (rowIndex === 0 || row.companyName != list[rowIndex - 1].companyName) {
      let rowspan = 0;
      list.forEach((element) => {
        if (element.companyName === row.companyName) {
          rowspan++;
        }
      });
      return [rowspan, 1];
    } else {
      return [0, 0];
    }
  }
};
</script>
<template>
  <div class="btns">
    <el-button type="primary" @click="onExport">导出</el-button>
  </div>
  <h2>养老/托育</h2>
  <CustomTable
    border
    class="custom_table"
    :objectSpanMethod="(e) => rowSpan(e, childElderList)"
    :index="false"
    :selection="false"
    :indexWidth="100"
    :tableData="childElderList"
    :isPaging="false"
    :tableOption="childElderlyColumns"
  />
  <h2>社商/邻里</h2>
  <CustomTable
    border
    class="custom_table"
    :index="false"
    :selection="false"
    :indexWidth="100"
    :tableData="communityList"
    :isPaging="false"
    :tableOption="communityColumns"
  />
  <h2>医馆/实验室</h2>
  <CustomTable
    border
    class="custom_table"
    :objectSpanMethod="(e) => rowSpan(e, labList)"
    :index="false"
    :selection="false"
    :indexWidth="100"
    :tableData="labList"
    :isPaging="false"
    :tableOption="labHospitalColumns"
  />
  <h2>文创上刊率</h2>
  <CustomTable
    border
    class="custom_table"
    :index="false"
    :selection="false"
    :indexWidth="100"
    :tableData="culturePubList"
    :isPaging="false"
    :tableOption="culturalLvColumns"
  />
  <h2>文创合同金额</h2>
  <CustomTable
    border
    class="custom_table"
    :index="false"
    :selection="false"
    :indexWidth="100"
    :tableData="cultureList"
    :isPaging="false"
    :tableOption="culturalColumns"
  />
  <h2>领创投运点数</h2>
  <CustomTable
    border
    class="custom_table"
    :index="false"
    :selection="false"
    :indexWidth="100"
    :tableData="lingchuangPointList"
    :isPaging="false"
    :tableOption="lingchuangPointColumns"
  />
  <h2>领创收入</h2>
  <CustomTable
    border
    class="custom_table"
    :index="false"
    :selection="false"
    :indexWidth="100"
    :tableData="lingchuangIncomeList"
    :isPaging="false"
    :tableOption="lingchuangColumns"
  />

  <h2>体育公司</h2>
  <CustomTable
    border
    class="custom_table"
    :index="false"
    :selection="false"
    :indexWidth="100"
    :tableData="gymList"
    :isPaging="false"
    :tableOption="gymColumns"
  />

  <h2>城安公司</h2>
  <CustomTable
    border
    class="custom_table"
    :index="false"
    :selection="false"
    :indexWidth="100"
    :tableData="chenganList"
    :isPaging="false"
    :tableOption="chenganColumns"
  />
</template>
<style lang="scss" scoped>
@import url("@/styles/daily.scss");
.btns {
  display: flex;
  justify-content: flex-end;
  //   padding-bottom: 20px;
}

:deep(.el-table) {
  .el-table__inner-wrapper {
  }
  .el-table__cell {
    // border: 1px solid var(--el-table-border);
  }
  .el-table__header {
    thead {
      .el-table__cell {
        background: var(--el-fill-color-light);
      }
    }
  }
}
</style>
